// pages/report/report.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contrastArr: [],
    chooseId: [],
    reportObj: {},
    tabdex: "",
    popshow: false,
    page: 0,
    pagesize: 10,
    list: [],
    status: "",
    sick_index: "",
    type: "",
    tablist: [{
      types: "所有人",
      list: [{
          items: "我",
          checked: false
        },
        {
          items: "家庭成员",
          checked: false
        },
        {
          items: "亲戚",
          checked: false
        },
        {
          items: "朋友",
          checked: false
        },
        {
          items: "其他",
          checked: false
        },
      ]
    }, {
      types: "报告类型",
      list: [{
          items: "检验报告",
          checked: false
        },
        {
          items: "基因报告",
          checked: false
        },
        {
          items: "体检报告",
          checked: false
        },
      ]
    }, {
      types: "解读状态",
      list: [{
          items: "未解读",
          checked: false
        },
        {
          items: "已解读",
          checked: false
        },
      ]
    }, ],
    //states 0 检验报告  1  基因报告  2  体检报告
    sicklist: [
      // {
      //   headimg:"../../../images/xzadd.png",
      //   names:"张三",
      //   sex:"男",
      //   age:"23",
      //   times:"2019年12月8日",
      //   hospital:"山西省白求恩医院",
      //   numbers:"8529638525623",
      //   states:0,
      // }, {
      //   headimg: "../../../images/xzadd.png",
      //   names: "张三",
      //   sex: "男",
      //   age: "23",
      //   times: "2019年12月8日",
      //   hospital: "山西省白求恩医院",
      //   numbers: "8529638525623",
      //   states: 1,
      // }, {
      //   headimg: "../../../images/xzadd.png",
      //   names: "张三",
      //   sex: "男",
      //   age: "23",
      //   times: "2019年12月8日",
      //   hospital: "山西省白求恩医院",
      //   numbers: "8529638525623",
      //   states: 2,
      // },
    ],
  },
  submit: function (e) {
    var that = this
    var chooseId = e.detail.value.oid
    var str = JSON.stringify(chooseId)
    if (chooseId.length < 2) {
      wx.showToast({
        title: '至少选择两项',
      })
    } else {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/contrast_results/contrast_results?chooseId=' + str,
      })
    }
  },
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: ""
      })
    } else {
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex
      })
    }
  },
  itemchecked(e) {
    let arrs = this.data.tablist,
      i = this.data.tabdex,
      dex = e.currentTarget.dataset.dex
    arrs[i].list.map(item => {
      item.checked = false
    })
    arrs[i].types = arrs[i].list[dex].items
    arrs[i].list[dex].checked = true
    this.setData({
      tablist: arrs,
      popshow: false,
      tabdex: ""
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var openid = wx.getStorageSync('openid')

    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getAlltijianbaogao('', '', '')
  },



  //查看报告
  reportDetailClick: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/diagReport/diagReport?id=' + id + '&ifzj=0',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var sick_index = that.data.sick_index;
    var type = that.data.type;
    var status = that.data.status;
    that.getAlltijianbaogao(sick_index, type, status);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //查询我的所有体检报告
  getAlltijianbaogao: function (sick_index, type, status) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/user.tijianjiedu',
      data: {
        openid: wx.getStorageSync('openid'),
        sick_index: sick_index,
        status: status,
        type: type,
        page: that.data.page,
        pagesize: that.data.pagesize,
      },
      success: function (res) {
        console.log(res)
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data)
        })
      }
    })
  }
})